package com.blackline.auto.dev1904;

import static org.junit.Assert.fail;

import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

import com.blackline.declareUI.UI;
import com.blackline.parameters.Parameters;
import com.blackline.auto.common.*;

/**
 * @author Allen
 * @version May 15, 2013
 * <p>This is to help verifying DEV-1904
 */
public class DEV1904 {
	
	private WebDriver driver;
	private StringBuffer verificationErrors = new StringBuffer();
	private static Logger logger=Logger.getLogger(DEV1904.class);
	UI UI=new UI();
	Parameters parameters;
	@Before
	public void setUp() throws Exception {
		FirefoxProfile profile=new FirefoxProfile();
		profile.setEnableNativeEvents(true);
		parameters=new Parameters("parameters.xml");

		driver = new FirefoxDriver();
		driver.manage().window().maximize();
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		UI.declareAllUI(driver);
	}
	
	@Test
	public void Starter_report_sysadmin() throws Exception {
		
		String starterSite = "https://test.blacklineondemand.com/XBOSoftStarter/Modules/Reports/Reporting.aspx";
		String user = "report.sysadmin";
		String password = "Password01";

		logger.info("You've selected site: " + starterSite + " with: " + user);
		UI.LogonPage.Login(driver, starterSite,user, password);
		Thread.sleep(5000);
		CommonMethods.takeScreenShot(this.getClass(), driver);
		UI.Reporting.My_scheduled_Report_nodeInLeftTree.click();
		Thread.sleep(5000);
		CommonMethods.takeScreenShot(this.getClass(), driver);

	}
	
	@Test
	public void Starter_gladmin() throws Exception {
		
		String starterSite = "https://test.blacklineondemand.com/XBOSoftStarter/Modules/Reports/Reporting.aspx";
		String user = "gladmin";
		String password = "Helsinki2012?";

		logger.info("You've selected site: " + starterSite + " with: " + user);
		UI.LogonPage.Login(driver, starterSite,user, password);
		Thread.sleep(5000);
		CommonMethods.takeScreenShot(this.getClass(), driver);
		UI.Reporting.My_scheduled_Report_nodeInLeftTree.click();
		Thread.sleep(5000);
		UI.Reporting.Schedule_Name_text_field.sendKeys("Alisa");
		Thread.sleep(500);
		UI.Reporting.Schedule_Name_text_field.sendKeys(Keys.RETURN);
		Thread.sleep(3000);
		CommonMethods.takeScreenShot(this.getClass(), driver);

	}
	
	
	@Test
	public void Internal2_gladmin() throws Exception {
		
		String starterSite = "https://test.blacklineondemand.com/Internal2/Modules/Reports/Reporting.aspx";
		String user = "gladmin";
		String password = "Helsinki2012?";

		logger.info("You've selected site: " + starterSite + " with: " + user);
		UI.LogonPage.Login(driver, starterSite,user, password);
		Thread.sleep(5000);
		CommonMethods.takeScreenShot(this.getClass(), driver);
		UI.Reporting.My_scheduled_Report_nodeInLeftTree.click();
		Thread.sleep(5000);
		UI.Reporting.Schedule_Name_text_field.sendKeys("Alisa");
		Thread.sleep(500);
		UI.Reporting.Schedule_Name_text_field.sendKeys(Keys.RETURN);
		Thread.sleep(3000);
		CommonMethods.takeScreenShot(this.getClass(), driver);

	}
	
	@After
	public void tearDown() throws Exception {
//		CommonMethods.takeScreenShot(this.getClass(), driver);
 		driver.close();
 		driver.quit();
		String verificationErrorString = verificationErrors.toString();
		if (!"".equals(verificationErrorString)) {
			fail(verificationErrorString);
		}
	}
	
}
